import { Column, Entity, Index, PrimaryGeneratedColumn } from 'typeorm';

@Index('email', ['email'], { unique: true })
@Entity('users', { schema: 'vote' })
export class Users {
  @PrimaryGeneratedColumn({ type: 'int', name: 'id' })
  id: number;

  @Column('enum', {
    name: 'role',
    comment: '用户角色：user（普通用户）/ admin（工作人员）',
    enum: ['user', 'admin'],
    default: () => "'user'",
  })
  role: 'user' | 'admin';

  @Column('varchar', {
    name: 'email',
    unique: true,
    comment: '邮箱',
    length: 255,
  })
  email: string;

  @Column('varchar', { name: 'password', comment: '密码', length: 255 })
  password: string;

  @Column('tinyint', {
    name: 'is_verified',
    nullable: true,
    comment: '邮箱是否已验证，0否，1是',
    default: () => "'0'",
  })
  isVerified: number | null;

  @Column('int', {
    name: 'created_at',
    comment: '创建时间',
    default: () => "'0'",
  })
  createdAt: number;

  @Column('int', {
    name: 'updated_at',
    comment: '更新时间',
    default: () => "'0'",
  })
  updatedAt: number;
}
